import java.util.TreeSet;

//Student类有三个属性：姓名（String类型）、年龄（int类型）、
// 成绩（double类型）。请使用TreeSet对Student类进行排序，排序条件为：
// 首先按照年龄进行升序排序，如果年龄相同则按照成绩进行降序排序。
public class TreeSetSort implements Comparable<TreeSetSort>{


    private String name;
    private int age;
    private int score;

    public TreeSetSort(String name, int age,int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public TreeSetSort() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    public void setScore(int score){
        this.score = score;
    }
    public double getScore(){
        return score;
    }


    @Override
    public String toString() {
        return "TreeSetSort{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    //重写compareTo方法，首先按照年龄进行升序排序，如果年龄相同则按照成绩进行降序排序
    public int compareTo(TreeSetSort o) {
        if (this.age !=  o.age){
            return this.age - o.age;
        }else {
            return this.score - o.score;
        }
    }







    public static void main(String[] args) {
        TreeSetSort s1 = new TreeSetSort("lisi", 24,98);
        TreeSetSort s2 = new TreeSetSort("wangwu", 25,89);
        TreeSetSort s3 = new TreeSetSort("zhangsan", 23,100);
        TreeSetSort s4 = new TreeSetSort("zhaoliu", 23,87);

        //创建TreeSet对象
        TreeSet<TreeSetSort> ts = new TreeSet<>();
        ts.add(s1);
        ts.add(s2);
        ts.add(s3);
        ts.add(s4);
        System.out.println(ts);
    }

}

